﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 资源加载管理器  
/// </summary>
public class ResMgr : SingleTon<ResMgr>
{
    /// <summary>
    /// 资源加载方法
    /// </summary>
    /// <param name="name"></param>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    public T load<T>(string name,Transform father=null )where T:Object
    {
        print("load");
        T res = Resources.Load<T>(name);
        if (res is GameObject prefab)
        {
            // 使用带父节点的实例化方法
            GameObject instance = father != null
                ? GameObject.Instantiate(prefab, father, false)
                : GameObject.Instantiate(prefab);

            // 统一重置变换
            Transform trans = instance.transform;
            trans.localPosition = Vector3.zero;
            trans.localRotation = Quaternion.identity;
            trans.localScale = Vector3.one; // 新增缩放重置

            return instance as T;
        }
        return res;
    }
}
